﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Refugees.Views.Windows
{
    /// <summary>
    /// Логика взаимодействия для AddEmployee.xaml
    /// </summary>
    public partial class PersonalData : Window
    {
        Repositories.PersonalDataRepository personalDataRepository = new Repositories.PersonalDataRepository();
        Models.PersonalData personalData;
        public PersonalData()
        {
            InitializeComponent();
            this.personalData = new Models.PersonalData();
            personalDataRepository.AddPersonalDataUser(this.personalData);
            Load();
        }

        public PersonalData(Models.PersonalData personalData)
        {
            InitializeComponent();
            if (personalData == null)
            {
                personalData = new Models.PersonalData();
                personalDataRepository.AddPersonalDataUser(personalData);
            }
            this.personalData = personalData;
            Load();
        }

        private void Load()
        {
            this.DataContext = personalData;
        }

        private void SaveClick(object sender, RoutedEventArgs e)
        {
            if (Repositories.ModelRepository.Save())
            {
                MessageBox.Show("Данные сохранены успешно");
            }
            else
            {
                MessageBox.Show("Данные не сохранены. Повторите попытку позже или проверьте данные");
            }
        }

        private void BackClick(object sender, RoutedEventArgs e)
        {
            new Personals().Show();
            Close();
        }
    }
}
